<?php
 
load_control('datatable');

class docmanager_list extends datatable
{
	var $count;
	
	function docmanager_list($id, $user_id, $link_id=0, $return_zero=true, $form_name='0', $return_to='')
	{
		global $GO_CONFIG, $GO_SECURITY, $GO_MODULES, $GO_LANGUAGE, $GO_THEME, $GO_LINKS;
		
		$this->datatable($id, false, $form_name);
		$this->set_attribute('style','width:100%;margin-bottom:20px;margin-top:0px;');
		$return_to = !empty($return_to) ? $return_to : $_SERVER['PHP_SELF'];
		
		require($GO_LANGUAGE->get_language_file('docmanager'));
		require_once($GO_MODULES->modules['docmanager']['class_path']."docmanager.class.inc");
		
		$docmanager = new docmanager();
		// 删除记录 $docmanager->delete_docmanager($id)为删除指定记录方法，须实现
		if($this->task == 'delete')
		{
			foreach($this->selected as $delete_docmanager_id)
			{
				$delete_docmanager_id =str_replace('4:', '', $delete_docmanager_id);
				$docmanager->delete_docmanager($delete_docmanager_id);
			}
		}
		
		$links = $link_id > 0 ? $GO_LINKS->get_links($link_id, 4) : false;
		// 错误回馈
		if (isset($feedback))
		{
			$p = new html_element('p', $feedback);
			$p->set_attribute('class','Error');
			$this->add_html_element($p);
		}
/*搜索部分－－开始*/
		$tab = new table('search_table');
		
		$row = new table_row();
		$cell = new table_cell();

		$cell->add_html_element(new html_element('a', '关键字'));
		$cell->add_html_element(new input('text','search_name'));
		$cell->add_html_element(new button('搜索',"javascript:document.location='".htmlspecialchars($return_to)."';"));	
		$cell->add_html_element(new html_element('p'));
		$row->add_cell($cell);
		$tab->add_row($row);
		$this->add_outerhtml_element($tab);
/*搜索部分－－结束	*/
/*表格头部信息－－开始*/
		// 文档名称单元格
		$this->add_column(new table_heading($lang_docmanager['doc_name'], 'doc_name'));
		// 数据表名称单元格
		$this->add_column(new table_heading($lang_docmanager['doc_db_name'], 'doc_db_name'));		
		// 最近修改日期单元格
		$this->add_column(new table_heading($lang_docmanager['modified_date'], 'modified_date'));
/*表格头部信息－－结束*/
//		$th = new table_heading('&nbsp;');
//		$this->add_column($th);

		// 此处需要获得文档总数并将其赋值给$this->count变量
		$this->count = 1;
		// 设置分页
		$this->set_pagination($this->count);
/*表格内容－－开始*/

		if($this->count > 0)
		{	// 遍历所有文档记录
			//while($doc_manager->next_record())
			//{
				// 数据替换区域
				$id = '1';
				$doc_name='立项审批表';
				$doc_db_name='build_project';
				$modified_date='2008-04-25 10:00:00';
							
				$row = new table_row('4:'.$id);
				// 双击表格某一行，显示该行的信息
				$row->set_attribute('ondblclick', 
							"javascript:window.location.href='".					
							$GO_MODULES->modules['message']['url'].'view_docmanager.php?docmanager_id='.$docmanager->f('id').
							'&return_to='.urlencode($return_to)."';");	
				
				// 文档名称单元格
				$cell = new table_cell(htmlspecialchars($doc_name));
				$cell->set_attribute('width','40%');
				$row->add_cell($cell);
				// 数据表名称
				$cell = new table_cell(htmlspecialchars($doc_db_name));
				$cell->set_attribute('width','30%');
				$row->add_cell($cell);
				// 最近修改日期单元格
				$cell = new table_cell(get_timestamp($modified_date));
				$cell->set_attribute('width','30%');
				$row->add_cell($cell);				
/*				// 操作单元格
				$cell = new table_cell();
				$cell->set_attribute('width','20%');
				$link = new html_element('a','参看 ');
				$link->set_attribute('href','view_docmanager.php');
				$cell->add_html_element($link);
				$link = new html_element('a','修改');
				$link->set_attribute('href','view_docmanager.php');
				$cell->add_html_element($link);
				$row->add_cell($cell);
*/				
				// 将以上单元格加入该行			
				$this->add_row($row);	
			//}		
		}else
		{
			if($return_zero)
			{
				$row = new table_row();
				$cell = new table_cell($no_no_message);
				$cell->set_attribute('colspan','99');
				$row->add_cell($cell);
				$this->add_row($row);
			}else
			{
				$this->innerHTML = '';
				return false;
			}
		}
/*表格内容－－结束	*/
	}
}
